# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/10/21 15:46
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : edge_detection_skimage.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage.io import imread
from skimage import filters, util, feature
from DIP_experiment_5.util import contrast_show

# 以灰度图形式读入图像
im_path = "../experiment_fig/chess.jpg"
im = imread(im_path, as_gray=True)  # 读取后图像已经归一化到[0.0,1.0]
# 对原始图像添加高斯噪声
noise_im = util.random_noise(im, mode='gaussian', seed=1)
# Prewitt算子提取噪声图像的边缘
prewitt_h_edge = filters.prewitt_h(noise_im)
prewitt_v_edge = filters.prewitt_v(noise_im)
# Canny算子提取噪声图像的边缘
canny_im = feature.canny(noise_im, sigma=1)
im_dict = {"noise im": noise_im, "prewitt_h": prewitt_h_edge,
           "prewitt_v": prewitt_v_edge, "canny im": canny_im}
contrast_show(im_dict, (2, 2),hspace=0.3)
